package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import game.Jeton;

@SuppressWarnings("serial")
public class Fenetre extends JFrame implements ActionListener,MouseListener {

	
	private JLabel jl;
	private JMenuBar jmb;
	private JMenu jm1;
	private JMenuItem jmi1;
	private JMenuItem jmi2;
	private JMenu jm2;
	private JMenuItem jmi3;
	private JMenuItem jmi4;

	private JPanel jp;
	private JLabel Let1;
	private JLabel Let2;
	private JLabel Let3;
	private JLabel Let4;
	private JLabel Let5;
	private JLabel Let6;
	private JLabel Let7;

	public Fenetre(String titre) {
		super(titre); setSize(500,500);


		jmb = new JMenuBar();
		this.setJMenuBar(jmb);
		jm1 = new JMenu("Menu1");
		jmb.add(jm1);
		jmi1 = new JMenuItem("Arriver");
		jm1.add(jmi1);
		jmi2 = new JMenuItem("Depart");
		jm1.add(jmi2);
		jm2 = new JMenu("Aide");
		jm2.setMnemonic('A');
		jmb.add(jm2);
		jmi3 = new JMenuItem("A propos");
		jmi3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		jm2.add(jmi3);
		jmi4 = new JMenuItem("Quitter");
		jm2.add(jmi4);
		jmi1.addActionListener(this);
		jmi2.addActionListener(this);
		jmi3.addActionListener(this);
		jmi4.addActionListener(this);
		jl = new JLabel();
		Container conteneur = this.getContentPane();
		conteneur.add(jl,BorderLayout.SOUTH);


		jp= new JPanel();
		jp.setBackground(new Color(132,132,132));



		JButton res=new JButton();
		res.setPreferredSize(new Dimension(50,50));
		ImageIcon aux = new ImageIcon("images/lettres/C.png");
		Image im = aux.getImage();
		int hauteur =50;// res.getHeight(); //nouvelle taille de l'image
		int largeur = 50;//res.getWidth(); //nouvelle taille de l'image
		im = im.getScaledInstance(largeur,hauteur,Image.SCALE_DEFAULT);

		res.setIcon(new ImageIcon(im));


		//res=new JButton(new ImageIcon("images/lettres/C.png"));
		//ImageIcon aux = new ImageIcon("images/wallpaper-1871745.jpg");


		Let1=Jeton.Resize("images/Lettres/A.png");
		Let2=Jeton.Resize("images/Lettres/G.png");
		Let3=Jeton.Resize("images/Lettres/D.png");
		Let4=Jeton.Resize("images/Lettres/B.png");
		Let5=Jeton.Resize("images/Lettres/Y.png");
		Let6=Jeton.Resize("images/Lettres/K.png");
		Let7=Jeton.Resize("images/Lettres/I.png");

		Let7.setName("pipi");//modif le nom du jlabel

		Let7.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let7);
		Let6.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let6);
		Let5.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let5);
		Let4.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let4);
		Let3.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let3);
		Let2.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let2);
		Let1.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));
		jp.add(Let1);


		jp.add(res);

		

		jp.setLayout(null);



		res.setBounds(51, 51,50, 50);
		Let1.setBounds(0, 0, 50, 50);
		Let2.setBounds(51, 0, 50, 50);
		Let3.setBounds(102, 0, 50, 50);
		Let4.setBounds(153, 0, 50, 50);
		Let5.setBounds(204, 0, 50, 50);
		Let6.setBounds(255, 0, 50, 50);
		Let7.setBounds(306,0 , 50, 50);

		this.add(jp);
		this.repaint(10);
		setResizable(false);
		setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		addMouseListener(this);
	}

	public void actionPerformed(ActionEvent ae) {
		Object source = ae.getSource();
		if (source == jmi1) {
			jl.setText(this.Let7.getName());
			Let7.setBorder(BorderFactory.createLineBorder(new Color(3,3,3)));
			Let7.setBackground(new Color(12,12,240));
		} 
		else if (source == jmi2) {
			jl.setText(this.Let7.getToolTipText());
			Let7.setBorder(BorderFactory.createLineBorder(new Color(198, 226, 255)));

		} 
		else if (source == jmi3) {
			JOptionPane.showMessageDialog(this, "test - menus - java 2A");
		} else if (source == jmi4) {
			System.exit(0);
		}
	}



	boolean ch1=true;
	boolean ch2=true;
	boolean ch3=true;
	boolean ch4=true;
	boolean ch5=true;
	boolean ch6=true;
	boolean ch7=true;
	int ancien=-1;

	public static void main(String[] args) {
		@SuppressWarnings("unused")
		Fenetre f = new Fenetre("test - menus");
	}

	@Override
	public void mouseClicked(MouseEvent e) 
	{

		int xmsg=e.getX();
		int  ymsg=e.getY();



		if ((xmsg >= 00 && xmsg < 51)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch1)	
			{
				ch1=false;
				
				efface(ancien);
				ancien=1;
				Let1.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
			}
			else
			{
				Let1.setBorder(null);
				ch1=true;
			}
		}

		if ((xmsg >= 51 && xmsg < 101)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch2)	
			{
				ch2=false;
				
				efface(ancien);
				ancien=2;
				Let2.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
			}
			else
			{
				Let2.setBorder(null);
				ch2=true;
			}
		}

		if ((xmsg >= 101 && xmsg < 151)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch3)	
			{
				ch3=false;
				efface(ancien);
				ancien=3;
				Let3.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
			}
			else
			{
				Let3.setBorder(null);
				ch3=true;
			}
		}

		if ((xmsg >= 151 && xmsg < 201)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch4)	
			{
				ch4=false;
				efface(ancien);
				Let4.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
				ancien=4;
			}
			else
			{
				Let4.setBorder(null);
				ch4=true;
			}
		}

		if ((xmsg >= 201 && xmsg < 251)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch5)	
			{
				ch5=false;
				efface(ancien);
				Let5.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));
				ancien=5;
			}
			else
			{
				Let5.setBorder(null);
				ch5=true;
			}
		}

		if ((xmsg >= 251 && xmsg < 301)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch6)	
			{
				ch6=false;
				efface(ancien);
				Let6.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
				ancien=6;
			}
			else
			{
				Let6.setBorder(null);
				ch6=true;
			}
		}

		if ((xmsg >= 301 && xmsg < 351)&&(ymsg>=0 && ymsg<=50))
		{
			if (ch7)	
			{
				ch7=false;
				efface(ancien);
				Let7.setBorder(BorderFactory.createLineBorder(Color.BLUE, 3));	
				ancien=7;
			}
			else
			{
				Let7.setBorder(null);
				ch7=true;
			}
		}

		
		
		repaint();

	}

	private void efface(int ancien2) {
		switch (ancien)
		{
		case 1 :
			Let1.setBorder(null);
			break;
		case 2 :
			Let2.setBorder(null);
			break;
		case 3 :
			Let3.setBorder(null);
			break;
		case 4 :
			Let4.setBorder(null);
			break;
		case 5 :
			Let5.setBorder(null);
			break;
		case 6 :
			Let6.setBorder(null);
			break;
		case 7 :
			Let7.setBorder(null);
			break;

		}
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}
}
